<style scoped lang="scss">
.mapWrapper {
  display: flex;
  height: 32px;
  justify-content: flex-start;
  align-items: center;
  border-radius: 4px;
  background-color: #f7f7f7;
  margin:2px 0;
}
.labelWrapper {
  display: flex;
  height:32px;
  width:150px;
  justify-content: flex-end;
  align-items: center;
  padding: 0 5px;
  border: 1px solid #dcdee2;
  border-right:none;
  border-radius: 4px 0px 0px 4px;
  font-size: 14px;
  background-color: #f7f7f7;
}
.labelTip {
  height:100%;
}
.editor {
  height:100%;
  flex:1 1 auto;
  border: none;
  padding:0;
}
.mark {
  width:5px;
  height:32px;
  background-color: var(--primary-color);
  border-color: var(--primary-color);
  margin-right:2px;
  opacity: 0.6;
}
.action {
  width:20px;
  margin-right: 5px;
  margin-left:5px;
  cursor: pointer;
  line-height: 2;
  text-align: center;
}
</style>
<template>
  <div class="mapWrapper">
    <div v-if="mark" class="mark"></div>
    <Tooltip class="labelTip" placement="top" :content="tip" :disabled="!tip" transfer>
      <div class="labelWrapper" :style="labelStyle"><span>{{label}}</span></div>
    </Tooltip>
    <slot name="prepend"></slot>
    <cfgCell class="editor" v-model="editValue" :config="config" @change="change"></cfgCell>
    <slot name="append"></slot>
    <div v-if="addField" class="action" @click="$emit('addField',editValue)">+</div>
    <div v-if="removeField" class="action" @click="$emit('removeField',editValue)">-</div>
  </div>
</template>

<script>
import cfgCell from "./cfg-cell";
export default {
  name: "cfg-empty",
  components: {cfgCell},
  model: {
    prop: 'value',
    event: 'change'
  },
  data() {
    return {
      editValue:null
    }
  },
  props: {
    value:{
      default:()=>{
        return null;
      }
    },
    labelStyle: {
      default: () => {
        return {};
      }
    },
    config: {
      default: () => {
        return {};
      }
    },
    label: {
      default: () => {
        return '';
      }
    },
    tip: {
      default: () => {
        return null;
      }
    },
    addField: {
      default: () => {
        return false;
      }
    },
    removeField: {
      default: () => {
        return false;
      }
    },
    mark:{
      default: () => {
        return true;
      }
    }
  },
  computed: {},
  beforeMount() {

  },
  mounted() {
    this.editValue=this.value;
  },
  watch: {
    value:function(newVal){
      this.editValue=newVal;
    }
  },
  methods: {
    change(){
      this.$emit('change',this.editValue);

    }
  }
}
</script>
